package com.yxs.yapp.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;

public class Ysys {
    private Ysys() {}
    
    /**
     * 显示退出确认对话框
     * @param activity 当前Activity
     */
    public static void ExitApp(final Activity activity) {
        if (activity == null || activity.isFinishing()) {
            return;
        }
        
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle("确认退出")
            .setMessage("确定要退出应用吗？")
            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    exitApp(activity);
                }
            })
            .setNegativeButton("取消", null)
            .setCancelable(false)
            .show();
    }
    
    /**
     * 退出应用
     * @param activity 当前Activity
     */
    public static void exitApp(Activity activity) {
        if (activity != null) {
            Log.d("Lifecycle", "退出应用");
            activity.finishAffinity(); // 关闭所有Activity
            // 如果需要完全退出进程
            // System.exit(0);
        }
    }
    
    /**
     * 安全退出应用（完全结束进程）
     * @param activity 当前Activity
     */
    public static void exitAppCompletely(Activity activity) {
        if (activity != null) {
            Log.d("Lifecycle", "完全退出应用");
            activity.finishAffinity(); // 关闭所有Activity
            System.exit(0); // 完全退出进程
        }
    }
}
